<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use kartik\file\FileInput;
use kartik\select2\Select2;
use yii\web\JsExpression;
use app\common\Functions;

/* @var $this yii\web\View */
/* @var $model \yii2mod\rbac\models\BizRuleModel */
/* @var $form ActiveForm */
?>
<?php $form = ActiveForm::begin(); ?>

<div class="box-body">

    <?php

        // 隐藏的就直接输出，不参与排序
        echo  $form->field($model, 'id',['labelOptions'=>['style'=>'display:none']])->hiddenInput(['value' => $model->id]);

        // 构建展示膜版的数组
        $showForm = [];
        $showForm['cust_name']['form']       = $form->field($model, 'cust_name')->label( $prodSpecName . '客户名称')->textInput(['maxlength' => 64]);
        $showForm['cust_source_id']['form'] = $form->field($model, 'cust_source_id' )->label('客户来源')->dropDownList( $domainSources );
        $showForm['cust_type_id']['form']   = $form->field($model, 'cust_type_id'  )->label('客户类型')->dropDownList( $domainTypes );

        $showForm['region_id']['form']   = $form->field($model, "region_id")->label('地区') ->dropDownList( $model->getCityList(16));



        // 查找出客户的特性
        foreach ($attrSpecs as $attrSpec)
        {
            $prodAttr = $attrSpec->attrSpecs;

            // 文件
            if ($prodAttr->attr_spec_type_id==2)
            {
                $pluginOptions=[];
                $pluginOptions['initialPreviewAsData'] = true;
                $pluginOptions['showRemove'] = true;
                $pluginOptions['showUpload'] = false;

                if ($update)
                {
                    $pluginOptions['initialPreview'] = $p1[$prodAttr->attr_spec_id];
                }

                $showForm[$prodAttr->attr_field_name]['form']   =  $form->field($uploadModel, "file[{$prodAttr->attr_spec_id}][]")->label($prodAttr->attr_spec_name)->widget(FileInput::classname(), [
                    'options' => ['multiple' => false],
                    'pluginOptions' =>$pluginOptions,
                ])->fileInput();
            }
            elseif ($prodAttr->attr_spec_type_id==3) // 如果type等于3 需要进行字符转义
            {
                $showForm[$prodAttr->attr_field_name]['form']   =   $form->field($model, "localAttrsInsts[{$prodAttr->attr_spec_id}][content]")->label($prodAttr->attr_spec_name)->dropDownList(Functions::getDomains('attr_spec',$prodAttr->attr_spec_id));
            }
            elseif ($prodAttr->attr_spec_type_id==4) // 如果type等于4 说明是一组值
            {
                $showForm[$prodAttr->attr_field_name]['form']               =  $form->field($model, "localAttrsInsts[{$prodAttr->attr_spec_id}][content]")->label( '最小'. $prodAttr->attr_spec_name)->textInput(['maxlength' => 64]);
                $showForm[$prodAttr->attr_field_name . '_2']['form']       =  $form->field($model, "localAttrsInsts[{$prodAttr->attr_spec_id}][content2]")->label('最大'.$prodAttr->attr_spec_name)->textInput(['maxlength' => 64]);
            }
            else
            {
                $showForm[$prodAttr->attr_field_name]['form']   =   $form->field($model, "localAttrsInsts[{$prodAttr->attr_spec_id}][content]" )->label($prodAttr->attr_spec_name)->textInput(['maxlength' => 64]);
            }

            // 隐藏的直接输出
            echo $form->field($model, "localAttrsInsts[{$prodAttr->attr_spec_id}][attrSpecTypeID]",['labelOptions'=>['style'=>'display:none']])->hiddenInput(['value' => $prodAttr->attr_spec_type_id]);

        }

    ?>







        <?php foreach ($showForm as $postForm): ?>

                    <div class="col-md-4">
                        <?php  echo   $postForm['form'] ; ?>
                    </div>


        <?php endforeach; ?>









    <div class="col-md-12">
        <?php
      //  $showForm['remark']['form']   = $form->field($model, 'remark')->label(  '备注')->textarea(['rows'=>4,'maxlength' => 512]);
      echo  $form->field($model, 'remark')->label(  '备注')->textarea(['rows'=>4,'maxlength' => 512]);
        //echo $form->field($model, 'region_type_id')->label('区域类型')->textInput();
        ?>
    </div>









</div>
<div class="modal-footer">

    <?php echo Html::a(Yii::t('region', 'Cancel'), '', ['class' => 'btn btn-default','data-dismiss'=>'modal']); ?>
    <?php echo Html::submitButton($model->getIsNewRecord() ? Yii::t('region', 'Create') : Yii::t('region', 'Update'), [
        'class' => $model->getIsNewRecord() ? 'btn btn-success' : 'btn btn-primary', ]); ?>
</div>

<?php ActiveForm::end(); ?>